import { getPostingMsgPushNodeList } from '@/api/basic'
import { ref } from 'vue'

/**
 * (配件申请单/返厂单)过账消息推送节点列表服务
 */
export default function () {
  const getMsgPushNodeListLoading = ref(false)
  const msgPushNodeList = ref<Array<BaseInfoAPIResponse.PostingMsgPushNodeListItem>>([])

  const getMsgPushNodeList = async (type: 'sparePartApply' | 'repair') => {
    try {
      getMsgPushNodeListLoading.value = true
      const res = await getPostingMsgPushNodeList(type === 'sparePartApply' ? 1 : 2)
      getMsgPushNodeListLoading.value = false
      if (res.data.code === 20000) {
        msgPushNodeList.value = res.data.data.rows
        return ''
      }

      return res.data.message
    } catch (error) {
      getMsgPushNodeListLoading.value = false
      return '获取列表失败，请稍后重试'
    }
  }

  return {
    msgPushNodeList,
    getMsgPushNodeListLoading,
    getMsgPushNodeList,
  }
}
